<?php
namespace app\admin\controller;
use cmf\controller\AdminBaseController;
use app\common\logic\admin\Imgs;
use app\common\logic\home\Material;
use app\common\model\MaterialModel;
use app\common\model\AppUserModel;
use app\common\logic\Qiniu;
/**
 * 七牛云管理
 */
class QiniuController extends AdminBaseController
{
	//查询具体时间段内的大课堂图片列表
	public function index(Imgs $Imgs,Material $Material){
		
		return $this->fetch();
	}
	public function toDele(Imgs $Imgs){
		$param = $this->request->param();
		/*$param['start'] = '2019-02-01 00:00:00';
		$param['end'] = '2019-04-04 08:00:00';*/
		$data = $Imgs->deal($param);
		$this->assign('data',$data);
		//return $this->fetch();
	}
	//用户
	public function user(Material $Material){
		$param = $this->request->param();
		if(!empty($param['phone'])){
			$data_user = AppUserModel::where('phone',$param['phone'])->field('id,realName,schoolId')->find();
			$param['user_id'] = $data_user['id'];
			$data = $Material->getUserList($param);
			$this->assign('page',$data->render());
		}else{
			$data = '';
			$data_user = '';
		}
		
		$this->assign('data',$data);
		
		$this->assign('data_user',$data_user);
		return $this->fetch();
	}
	//删除
	public function toDelete(Material $Material,Qiniu $Qiniu){
		$param = $this->request->param();
		$param['ids'] = implode(',',$param['ids']);
		$data = $Material->getUserList($param);

		$BucketManager = $Qiniu->getObject();
        $bucket = $Qiniu->getBucket();

		foreach ($data as $key => $value) {
			foreach ($value['data'] as $key => $val) {
				$img = substr($val,strpos($val,'.com')+5);
				$rs = $BucketManager->delete($bucket,$img);
                //$rs = $Qiniu->delete($img);
			}
			MaterialModel::where('id',$value['id'])->update(['delete_time'=>date('Y-m-d H:i:s')]);
		}
		$this->success('成功','user?phone='.$param['phone']);
	}

	
	
}
